package com.itfenghuang.service.imp;

import com.itfenghuang.bean.Student;
import com.itfenghuang.mapper.StuMapper;
import com.itfenghuang.service.StuService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * 业务层实现类
 */
public class StuServiceImp implements StuService {
    @Override
    public List<Student> selectStuAndClaByCondition(Student stu) {
        InputStream is =null;
        List<Student> list=null;
        try {
            is = Resources.getResourceAsStream("MyBatisConfig.xml");
            SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
            SqlSession sqlSession = factory.openSession();
            StuMapper mapper = sqlSession.getMapper(StuMapper.class);
            list = mapper.selectStuAndClaByCondition(stu);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (is!=null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return list;
    }
}
